require('../less/courseDetail.less')
document.ready(function () {
    //   获取元素节点
    let startTraing = document.getElementById('startTraing')
    let returnBtn = document.getElementById('returnBtn') //返回按钮
    let lessName = document.getElementById('lessName') //课程名字
    let lesonDesc = document.getElementById('lesonDesc') //课程描述
    let imgPicker = document.getElementById('imgPicker') //图片加载
    let spendC = document.getElementById('spendC') //消耗卡路里



    returnBtn.addEventListener('click', function () {

        history.go(-1)
    })

    // 获取页面的courseId
    let courseId = window.location.search.split('=')[1]
    // console.log(courseId);
    window.$http.get(`/sports/courseDetail?id=${courseId}`, function (res) {
        if (res.status == 0) {
            render(res.data);
            // console.log(res.data.imgurl);
            // console.log(res);
            // console.log(res.data.courseId);
            
        }

    })

    // 渲染函数
    function render(data) {
        lessName.innerHTML = data.name;
        lesonDesc.innerHTML = data.desc
        imgPicker.src = `http://139.9.177.51:8099${data.imgurl}`
        spendC.textContent = data.calorie
        localStorage.setItem('frData',JSON.stringify(data.fragments))
        startTraing.addEventListener('click', function () {
            window.location.href = `./startTraining.html?courseId=${data.courseId}`

        })
    }


})